<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/base.css">
    <link rel="stylesheet" href="../css/form.css">
</head>
<body>
    <form>
        <span class="error">用户名或者密码错误！</span>
        <label>
            用户名：<input name="username" type="text">
        </label>
        <label>
            密&nbsp;&nbsp; 码：<input name="password" type="text">
        </label>
        <button>立即登录</button>
    </form>
    <script src="../../node_modules/jquery/dist/jquery.min.js"></script>
    <script>
        $('form').on('submit',async e=>{
            e.preventDefault()
            // console.log('ok');
            const res=await $.ajax({
                url:'http://localhost:9999/users/login',
                method:'post',
                data:$('form').serialize()
            })
            console.log(res);
            // 判断res中的内容
            if(res.code===0) return $('.error').show()
            if(res.code===1){
                $('.error').hide()
            // //oa一般都会向session中存储一些内容
            window.sessionStorage.setItem('token',res.token)
            window.sessionStorage.setItem('id',res.userId)
            // //跳转页面
            window.location.href='./index.html'
            }
        })


    </script>
</body>
</html>